home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 5 / MacMania 5.toast / / Internet software / NewsWatcher / NW Source / Source / about.c next >
Text File  |  1997-01-09  |  4KB  |  175 lines

  1. /*----------------------------------------------------------------------------
  2.  
  3.     about.c
  4.  
  5.     This module presents the about box.
  6.     
  7.     Copyright © 1994-1997, Northwestern University.
  8.  
  9. ----------------------------------------------------------------------------*/
  10.  
  11. #include <stdio.h>
  12.  
  13. #include "glob.h"
  14. #include "about.h"
  15. #include "text.h"
  16. #include "drawutil.h"
  17. #include "strutil.h"
  18. #include "windutil.h"
  19. #include "resutil.h"
  20. #include "help.h"
  21. #include "memutil.h"
  22.  
  23.  
  24.  
  25. #define kAboutText             128        /* resource id of about box text 'TEXT' resource */
  26.  
  27. #define kEggID                129        /* resource id of Easter egg 'STR#' resource */
  28.  
  29. #define kBigIconPictColor    128        /* resource id of big icon color picture */
  30. #define kBigIconPictBW        129        /* resource id of big icon B&W picture */
  31. #define kLogoPictColor        130     /* resource id of logo color picture */
  32. #define kLogoPictBW            131     /* resource id of logo B&W picture */
  33.  
  34.  
  35.  
  36. static short gDrawEasterEgg = 0;
  37.  
  38.  
  39.  
  40. /*----------------------------------------------------------------------------
  41.     DrawPanel.
  42.     
  43.     Draw the panel area.
  44.     
  45.     Entry:    wind = pointer to about window.
  46. ----------------------------------------------------------------------------*/
  47.  
  48. static void DrawPanel (WindowPtr wind)
  49. {
  50.     Rect r;
  51.     CStr255 versStr;
  52.     Str255 str;
  53.     CStr255 fmt;
  54.     TextStyle savedStyle;
  55.     OSErr err = noErr;
  56.     Str255 egg;
  57.     
  58.     GetPortTextStyle(&savedStyle);
  59.     SetRect(&r, 50, 10, 134, 85);
  60.     DrawColorPict(kBigIconPictColor, kBigIconPictBW, &r);
  61.     SetRect(&r, 180, 17, 390, 56);
  62.     DrawColorPict(kLogoPictColor, kLogoPictBW, &r);
  63.  
  64.     err = GetVersionString((StringPtr)versStr);
  65.     p2cstr((StringPtr)versStr);
  66.     if (err != noErr) goto exit;
  67.     GetCString(kStrVersion, fmt);
  68.     sprintf((char*)str, fmt, versStr);
  69.     c2pstr((char*)str);
  70.     MoveTo(183, 70);
  71.     TextFont(systemFont);
  72.     TextSize(12);
  73.     DrawString(str);
  74.     MoveTo(183, 88);
  75.     TextFont(applFont);
  76.     TextSize(9);
  77.     TextFace(bold | italic);
  78.     if (gDrawEasterEgg > 0) {
  79.         GetIndString(egg, kEggID, gDrawEasterEgg);
  80.         if (*egg == 0) {
  81.             gDrawEasterEgg = 0;
  82.         } else {
  83.             DrawString(egg);
  84.         }
  85.     }
  86.     if (gDrawEasterEgg == 0) {
  87.         GetCString(kStrAvailableMemoryFmt, fmt);
  88.         sprintf((char*)egg, fmt, GetMaxAvailableMemory() >> 10);
  89.         c2pstr((char*)egg);
  90.         DrawString(egg);
  91.     }
  92.     
  93. exit:
  94.  
  95.     SetPortTextStyle(&savedStyle);
  96. }
  97.  
  98.  
  99.  
  100. /*----------------------------------------------------------------------------
  101.     DoAboutNewsWatcher
  102.     
  103.     Present the about box.
  104.     
  105.     Exit:    function result = error code.
  106. ----------------------------------------------------------------------------*/
  107.  
  108. OSErr DoAboutNewsWatcher (void)
  109. {
  110.     Handle text;
  111.     Str255 title;
  112.     OSErr err = noErr;
  113.     WindowPtr wind;
  114.     
  115.     gDrawEasterEgg = 0;
  116.     GetPString(kStrAboutWindTitle, title);
  117.     if (CheckTextWindowAlreadyOpen(title)) return noErr;
  118.     err = MyGet1Resource('TEXT', kAboutText, &text);
  119.     if (err != noErr) return err;
  120.     err = MakeNewTextWindow(title, 100, DrawPanel, text, &wind);
  121.     MyReleaseResource(text);
  122.     return err;
  123. }
  124.  
  125.  
  126.  
  127. /*----------------------------------------------------------------------------
  128.     CheckAboutWindowEasterEgg
  129.     
  130.     Check for mouse down on big icon, display Easter egg.
  131.     
  132.     Entry:    wind = pointer to text window.
  133.             where = mouse down location, local coords.
  134.             modifiers = keyboard modifiers.
  135. ----------------------------------------------------------------------------*/
  136.  
  137. void CheckAboutWindowEasterEgg (WindowPtr wind, Point where, short modifiers)
  138. {
  139.     Rect r;
  140.     Str255 title, windTitle;
  141.     
  142.     if ((modifiers & optionKey) == 0) return;
  143.     GetPString(kStrAboutWindTitle, title);
  144.     GetWTitle(wind, windTitle);
  145.     if (!EqualString(title, windTitle, false, false)) return;
  146.     SetRect(&r, 50, 10, 134, 85);
  147.     if (!PtInRect(where, &r)) return;
  148.     gDrawEasterEgg++;
  149.     SetRect(&r, 180, 76, wind->portRect.right, 93);
  150.     InvalRect(&r);
  151. }
  152.  
  153.  
  154.  
  155. /*----------------------------------------------------------------------------
  156.     DoAboutWindowIconHelpBalloon 
  157.     
  158.     Handle the help ballown for the big icon in the about window.
  159.             
  160.     Entry:    wind = pointer to text window.
  161.             where = current mouse location in local coordinates.
  162. ----------------------------------------------------------------------------*/
  163.  
  164.  
  165. void DoAboutWindowIconHelpBalloon (WindowPtr wind, Point where)
  166. {
  167.     Rect r;
  168.     Point tip;
  169.     
  170.     SetRect(&r, 50, 10, 134, 85);
  171.     if (!PtInRect(where, &r)) return;
  172.     SetPt(&tip, 120, 77);
  173.     ShowHelpBalloon(tip, &r, 8);
  174. }
  175.